<template>
  <div class="qrcode-form">
    <add-base-form
      ref="addForm"
      v-if="opType === '1'"
      :form="form"
      :rules="formRules">
      <el-form-item :label="$t('文本地址')" prop="content">
        <el-input
          v-model="form.content"
          type="textarea"
          :rows="3" wrap="off"
          maxlength="300"
          :show-word-limit="false"
          clearable></el-input>
      </el-form-item>
      <el-form-item label-width="0">
        <span>{{ $t('支持的通配符') }}：$MAC$、$TERMNO$、$TERMGRP$  </span>
      </el-form-item>
      <el-form-item :label="$t('刷新间隔')">
        <input-hms v-model="form.attributes.refreshTimeArr"></input-hms>
      </el-form-item>
    </add-base-form>
    <edit-base-form
      ref="editForm"
      :form="form"
      v-else-if="opType === '2'"
      :rules="formRules">
      <el-form-item :label="$t('文本地址')">
        <el-input
          :value="form.content"
          style="height: 90px;"
          type="textarea"
          :rows="4" wrap="off"
          clearable></el-input>
      </el-form-item>
      <el-form-item :label="$t('刷新间隔')">
        <input-hms v-if="form.attributes" v-model="form.attributes.refreshTimeArr"></input-hms>
      </el-form-item>
    </edit-base-form>
  </div>
</template>

<script>
import AddBaseForm from './AddBaseForm'
import EditBaseForm from './EditBaseForm'
import InputHms from '../InputHms'

export default {
  components: {
    AddBaseForm,
    EditBaseForm,
    InputHms
  },
  props: {
    opType: {
      type: String,
      default: '1'
    },
    form: {
      type: Object,
      required: true
    }
  },
  data() {
    return {
      formRules: {
        name: [
          { required: true, message: '名称不能为空' }
        ],
        content: [
          { required: true, message: '文本地址不能为空' }
        ]
      }
    }
  },
  methods: {
    validate(cb) {
      if (this.opType === '1') {
        this.$refs.addForm.$refs.form.validate(cb)
      } else {
        this.$refs.editForm.$refs.form.validate(cb)
      }
    },
    clearValidate(params) {
      if (this.opType === '1') {
        this.$refs.addForm.$refs.form.clearValidate(params)
      } else {
        this.$refs.editForm.$refs.form.clearValidate(params)
      }
    }
  }
}
</script>

<style lang="scss" scoped>

</style>